<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DeepSeek + MCP 炒股实战平台</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#2563eb',
                        secondary: '#4f46e5',
                        success: '#10b981',
                        warning: '#f59e0b',
                        danger: '#ef4444',
                        neutral: {
                            100: '#f3f4f6',
                            200: '#e5e7eb',
                            700: '#374151',
                            800: '#1f2937',
                            900: '#111827',
                        }
                    },
                    fontFamily: {
                        sans: ['Inter', 'system-ui', 'sans-serif'],
                    },
                },
            }
        }
    </script>
    <link rel="stylesheet" href="/static/css/styles.css">
</head>
<body class="bg-neutral-100 min-h-screen">
    <!-- 顶部导航栏 -->
    <nav class="gradient-bg text-white shadow-lg">
        <div class="container mx-auto px-4 py-4 flex justify-between items-center">
            <div class="flex items-center space-x-2">
                <i class="fa fa-line-chart text-2xl"></i>
                <h1 class="text-xl font-bold">DeepSeek + MCP 炒股实战平台</h1>
            </div>
            <div>
                <button id="configBtn" class="bg-white text-primary px-4 py-2 rounded-md hover:bg-opacity-90 transition duration-300">
                    <i class="fa fa-cog mr-2"></i>配置
                </button>
            </div>
        </div>
    </nav>

    <!-- 主内容区 -->
    <main class="container mx-auto px-4 py-8">
        <!-- 配置模态框 -->
        <div id="configModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
            <div class="bg-white rounded-lg w-full max-w-2xl p-6 animate-fade-in">
                <div class="flex justify-between items-center mb-4">
                    <h2 class="text-2xl font-bold text-neutral-800">系统配置</h2>
                    <button id="closeConfigBtn" class="text-neutral-500 hover:text-neutral-700">
                        <i class="fa fa-times text-xl"></i>
                    </button>
                </div>
                <form id="configForm" class="space-y-4">
                    <div>
                        <label class="block text-neutral-700 mb-2">DeepSeek API Key</label>
                        <input type="text" id="apiKey" class="w-full px-4 py-2 border border-neutral-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary/50" placeholder="请输入API Key">
                    </div>
                    <div>
                        <label class="block text-neutral-700 mb-2">DeepSeek API URL</label>
                        <input type="text" id="apiUrl" class="w-full px-4 py-2 border border-neutral-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary/50" placeholder="API URL">
                    </div>
                    <div>
                        <label class="block text-neutral-700 mb-2">监控股票代码 (逗号分隔)</label>
                        <input type="text" id="stockSymbols" class="w-full px-4 py-2 border border-neutral-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary/50" placeholder="例如: 600519,000858,002594">
                        <p class="text-xs text-neutral-500 mt-1">上交所股票(6开头)和深交所股票(0/3开头)无需添加交易所后缀</p>
                    </div>
                    <div>
                        <label class="block text-neutral-700 mb-2">历史数据回溯天数</label>
                        <input type="number" id="lookbackDays" class="w-full px-4 py-2 border border-neutral-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary/50" placeholder="30">
                    </div>
                    <div class="flex justify-end">
                        <button type="submit" class="bg-primary text-white px-6 py-2 rounded-md hover:bg-primary/90 transition duration-300">
                            <i class="fa fa-save mr-2"></i>保存配置
                        </button>
                    </div>
                </form>
            </div>
        </div>

        <!-- 信号股票列表 -->
        <div class="bg-white rounded-lg shadow-md p-6 mb-8 card-shadow">
            <div class="flex justify-between items-center mb-4">
                <h2 class="text-2xl font-bold text-neutral-800">今日信号股票</h2>
                <button id="refreshSignalsBtn" class="bg-primary text-white px-4 py-2 rounded-md hover:bg-primary/90 transition duration-300">
                    <i class="fa fa-refresh mr-2"></i>刷新
                </button>
            </div>
            <div id="signalsLoading" class="hidden">
                <div class="text-center py-8">
                    <i class="fa fa-circle-o-notch fa-spin text-3xl text-primary mb-2"></i>
                    <p>正在获取有信号的股票...</p>
                </div>
            </div>
            <div id="noSignalsData" class="hidden">
                <div class="text-center py-8 text-neutral-500">
                    <i class="fa fa-info-circle text-3xl mb-2"></i>
                    <p>暂无符合条件的信号股票</p>
                </div>
            </div>
            <div id="signalsError" class="hidden">
                <div class="text-center py-8 text-danger">
                    <i class="fa fa-exclamation-circle text-3xl mb-2"></i>
                    <p id="signalsErrorMessage">获取信号股票失败</p>
                </div>
            </div>
            <div id="signalsTable" class="overflow-x-auto">
                <table class="w-full text-sm text-left text-neutral-700">
                    <thead class="text-xs text-neutral-700 uppercase bg-neutral-100">
                        <tr>
                            <th scope="col" class="px-4 py-3" data-sort="symbol">股票代码</th>
                            <th scope="col" class="px-4 py-3" data-sort="stock_name">股票名称</th>
                            <th scope="col" class="px-4 py-3" data-sort="latest_price">最新价</th>
                            <th scope="col" class="px-4 py-3" data-sort="buy_signals_count">买入信号</th>
                            <th scope="col" class="px-4 py-3" data-sort="sell_signals_count">卖出信号</th>
                            <th scope="col" class="px-4 py-3">操作</th>
                        </tr>
                    </thead>
                    <tbody id="signalsTableBody">
                        <!-- 信号股票数据将通过JavaScript动态填充 -->
                    </tbody>
                </table>
            </div>
            
            <!-- 分页控件 -->
            <div id="signalsPagination" class="mt-4 flex justify-between items-center hidden">
                <!-- 分页内容将通过JavaScript动态生成 -->
            </div>
        </div>

        <!-- 股票分析表单 -->
        <div class="bg-white rounded-lg shadow-md p-6 mb-8 card-shadow">
            <h2 class="text-2xl font-bold text-neutral-800 mb-4">股票分析</h2>
            <div class="flex flex-col md:flex-row gap-4">
                <div class="flex-1">
                    <label class="block text-neutral-700 mb-2">股票代码</label>
                    <div class="flex gap-2 relative">
                        <input type="text" id="stockSymbol" class="flex-1 px-4 py-2 border border-neutral-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary/50" placeholder="例如: 600519 或 000858" autocomplete="off">
                        <button id="analyzeBtn" class="bg-primary text-white px-6 py-2 rounded-md hover:bg-primary/90 transition duration-300 whitespace-nowrap">
                            <i class="fa fa-search mr-2"></i>分析
                        </button>
                        <!-- 自动提示下拉框 -->
                        <div id="stockSuggestions" class="absolute left-0 top-full mt-1 w-full max-h-60 overflow-y-auto bg-white border border-neutral-300 rounded-md shadow-lg z-10 hidden">
                            <!-- 提示项将在这里动态生成 -->
                        </div>
                    </div>
                    <p class="text-xs text-neutral-500 mt-1">支持A股代码，上交所(6开头)和深交所(0/3开头)</p>
                </div>
            </div>
            
            <!-- 搜索提示说明 -->
            <div class="mt-1 text-xs text-neutral-500">
                输入股票代码或名称的前几个字符即可获取智能提示
            </div>
        </div>

        <!-- 批量分析按钮 -->
        <div class="flex justify-end mb-4">
            <button id="batchAnalyzeBtn" class="bg-secondary text-white px-6 py-2 rounded-md hover:bg-secondary/90 transition duration-300">
                <i class="fa fa-line-chart mr-2"></i>批量分析监控股票
            </button>
        </div>

        <!-- 进度条显示容器 -->
        <div id="progressContainer" class="bg-white p-4 rounded-lg shadow-md mb-6 hidden">
            <h3 class="text-xl font-bold mb-3">分析进度</h3>
            <div class="flex items-center mb-2">
                <span id="progressSymbol" class="text-blue-600 font-medium"></span>
                <span id="progressStep" class="ml-2 text-gray-600"></span>
            </div>
            <div class="w-full bg-gray-200 rounded-full h-2.5">
                <div id="progressBar" class="bg-blue-600 h-2.5 rounded-full" style="width: 0%"></div>
            </div>
            <div class="text-right text-sm text-gray-500 mt-1">
                <span id="progressPercentage">0%</span>
            </div>
        </div>

        <!-- 分析结果区域 -->
        <div id="resultContainer" class="hidden bg-white rounded-lg shadow-md p-6 card-shadow animate-fade-in">
            <div class="flex justify-between items-start mb-6">
                <div>
                    <h2 class="text-2xl font-bold text-neutral-800" id="resultSymbol">股票分析结果</h2>
        <p class="text-neutral-500" id="resultTime"></p>
        <p class="text-sm text-neutral-500" id="resultSource"></p>
                </div>
                <div class="flex gap-2">
                    <button id="saveResultBtn" class="bg-success text-white px-4 py-2 rounded-md hover:bg-success/90 transition duration-300">
                        <i class="fa fa-download mr-2"></i>保存
                    </button>
                    <button id="shareResultBtn" class="bg-neutral-700 text-white px-4 py-2 rounded-md hover:bg-neutral-800 transition duration-300">
                        <i class="fa fa-share-alt mr-2"></i>分享
                    </button>
                </div>
            </div>

            <!-- 技术指标卡片 -->
            <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
                <div class="bg-neutral-100 p-4 rounded-lg">
                    <h3 class="text-neutral-700 text-sm font-medium mb-1">最新价格</h3>
                    <p class="text-2xl font-bold text-neutral-800" id="resultPrice">¥0.00</p>
                </div>
                <div class="bg-neutral-100 p-4 rounded-lg">
                    <h3 class="text-neutral-700 text-sm font-medium mb-1">RSI (14)</h3>
                    <p class="text-2xl font-bold text-neutral-800" id="resultRSI">0.00</p>
                </div>
                <div class="bg-neutral-100 p-4 rounded-lg">
                    <h3 class="text-neutral-700 text-sm font-medium mb-1">波动率</h3>
                    <p class="text-2xl font-bold text-neutral-800" id="resultVolatility">0.00%</p>
                </div>
                <!-- 成交量信息卡片 -->
                <div class="bg-neutral-100 p-4 rounded-lg">
                    <h3 class="text-neutral-700 text-sm font-medium mb-1">成交量</h3>
                    <p class="text-2xl font-bold text-neutral-800" id="resultVolume">0</p>
                </div>
                <div class="bg-neutral-100 p-4 rounded-lg">
                    <h3 class="text-neutral-700 text-sm font-medium mb-1">成交量MA5</h3>
                    <p class="text-2xl font-bold text-neutral-800" id="resultVolumeMA5">0</p>
                </div>
                <div class="bg-neutral-100 p-4 rounded-lg">
                    <h3 class="text-neutral-700 text-sm font-medium mb-1">量比</h3>
                    <p class="text-2xl font-bold text-neutral-800" id="resultVolumeRatio">0.00</p>
                </div>
            </div>

            <!-- 信号区域 -->
            <div class="mb-6">
                <h3 class="text-lg font-bold text-neutral-800 mb-3">交易信号</h3>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div class="border border-success/30 bg-success/5 p-4 rounded-lg">
                        <h4 class="flex items-center text-success font-medium mb-2">
                            <i class="fa fa-arrow-up mr-2"></i>买入信号
                        </h4>
                        <ul class="list-disc list-inside text-neutral-700" id="buySignals">
                            <li>无信号</li>
                        </ul>
                    </div>
                    <div class="border border-danger/30 bg-danger/5 p-4 rounded-lg">
                        <h4 class="flex items-center text-danger font-medium mb-2">
                            <i class="fa fa-arrow-down mr-2"></i>卖出信号
                        </h4>
                        <ul class="list-disc list-inside text-neutral-700" id="sellSignals">
                            <li>无信号</li>
                        </ul>
                    </div>
                </div>
            </div>

            <!-- DeepSeek分析 -->
            <div>
                <h3 class="text-lg font-bold text-neutral-800 mb-3">AI分析报告</h3>
                <div class="prose max-w-none text-neutral-700" id="resultAnalysis">
                    <p>分析报告将显示在这里...</p>
                </div>
            </div>
        </div>

        <!-- 批量分析结果 -->
        <div id="batchResultContainer" class="hidden mb-8 animate-fade-in">
            <h2 class="text-2xl font-bold text-neutral-800 mb-4">批量分析结果</h2>
            <div id="batchResults" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                <!-- 批量分析卡片将动态添加 -->
            </div>
        </div>

        <!-- 错误消息 -->
        <div id="errorContainer" class="hidden bg-danger/10 border border-danger/30 text-danger p-4 rounded-md mb-6">
            <p id="errorMessage"></p>
        </div>
    </main>

    <!-- 页脚 -->
    <footer class="bg-neutral-800 text-white py-6">
        <div class="container mx-auto px-4 text-center">
            <p>© 2026 DeepSeek + MCP A股实战平台 - 仅供学习参考，不构成投资建议</p>
            <p class="text-neutral-400 text-sm mt-2">投资有风险，入市需谨慎</p>
        </div>
    </footer>

    <!-- JavaScript 模块 -->
    <script type="module" src="/static/js/uiUtils.js"></script>
    <script type="module" src="/static/js/config.js"></script>
    <script type="module" src="/static/js/resultHandler.js"></script>
    <script type="module" src="/static/js/analysis.js"></script>
    <script type="module" src="/static/js/stockSuggestions.js"></script>
    <script type="module" src="/static/js/main.js"></script>
</body>
</html>